import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import RandomUtil from '@/RandomUtil';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 强冲
 **/
export default class BossSpell_StrongHit extends AbilityBase {
    static instance: BossSpell_StrongHit;
    buffType: AppBuffType = {
        id: 'buff_BossSpell_StrongHit',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        interval: 0.1,
        dur: 0.5,
        onInterval: this.onBuffInterval.bind(this),
        isDebuff: true,
    };
    onBuffInterval(buff: Buff) {
        let p = buff.getParent();
        let c = buff.getCaster();
        let x = GetUnitX(p);
        let y = GetUnitY(p);
        DestroyEffect(AddSpecialEffect('Abilities\\Weapons\\Blood\\BloodImpact.mdl', x, y));
        let ang = MathUtil.angleBetweenCoords(GetUnitX(c), GetUnitY(c), x, y);
        x += CosBJ(ang) * 15;
        y += SinBJ(ang) * 15;
        SetUnitX(p, x);
        SetUnitY(p, y);
    }
    constructor(id: string = 'Asm0') {
        super(id);
        BossSpell_StrongHit.instance = this;
        this.init();
        EventManager.onTakeAttack(this.onSpellEffect.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BuffUtil.addBuff(target, this.buffType.id, source);
        BossAbilityManagerInstance.text('强冲', source);
    }
    onSpellEffect(d: DamageEventData) {
        if (GetUnitAbilityLevel(d.source, this.id) == 0) return;
        let r = RandomUtil.randomPercent();
        if (r > 0.25) return;
        this.cast(0, 0, d.source, d.target, d);
        d.lastDamage += 500;
    }
}
